{template 'common/header'}
<ul class="nav nav-tabs">
	<li{if $do == 'upgrade'} class="active"{/if}><a href="{php echo create_url('cloud/upgrade');}">自动更新</a></li>
	<li{if $do == 'history'} class="active"{/if}><a href="{php echo create_url('cloud/upgrade/history');}">未成功的自动更新(需要手动更新)</a></li>
</ul>
{if $do == 'upgrade'}
<div class="main">
	<div style="padding:15px;">
		<div class="hide" id="tips">
		</div>
		<script type="text/javascript" src="http://addons.we7.cc/tips.php"></script>
		<div class="alert alert-error">
			<i class="icon-warning-sign"></i> 更新时请注意备份网站数据和相关数据库文件！官方不强制要求用户跟随官方意愿进行更新尝试！
		</div>
		<form action="" method="post" class="form-horizontal form" {if !$upgrade || !$upgrade['upgrade']}{else}onsubmit="return agreement();"{/if}>
			{if !$upgrade || !$upgrade['upgrade']}
			<table class="tb">
				<tr>
					<th>检查新版</th>
					<td>
						<input name="check-update" type="submit" value="立即检查新版本" class="btn" />
						<input type="hidden" name="token" value="{$_W['token']}" />
						<div class="help-block">当前系统未检测到有新版本, 你可以点击此按钮, 来立即检查一次.</div>
					</td>
				</tr>
			</table>
			{else}
			<table class="tb">
				<tr>
					<th>版本</th>
					<td>
						<label>
							<i class="icon-check-empty"> &nbsp; 系统当前版本: v{php echo IMS_VERSION}</i>
						</label>
						{if $upgrade['version'] != IMS_VERSION}
						<label>
							<i class="icon-check-empty"> &nbsp; 存在的新版本: v{$upgrade['version']}</i>
						</label>
						{/if}
						<div class="help-block">在一个发布版中可能存在多次补丁, 因此版本可能未更新</div>
					</td>
				</tr>
				<tr>
					<th>发布日期</th>
					<td>
						<label>
							<i class="icon-check-empty"> &nbsp; 系统当前Release版本: v{php echo IMS_RELEASE_DATE}</i>
						</label>
						{if $upgrade['release'] != IMS_RELEASE_DATE}
						<label>
							<i class="icon-check-empty"> &nbsp; 存在的新Release版本: v{$upgrade['release']}</i>
						</label>
						{/if}
						<div class="help-block">系统会检测当前程序文件的变动, 如果被病毒或木马非法篡改, 会自动警报并提示恢复至默认版本, 因此可能修订日期未更新而文件有变动</div>
					</td>
				</tr>
				{if $upgrade['announcement']}
				<tr>
					<th>更新通告</th>
					<td>
						{$upgrade['announcement']}
					</td>
				</tr>
				{/if}
				{if $upgrade['scripts']}
				<tr>
					<th>数据库变动</th>
					<td>
						<div class="help-block"><strong>注意: 重要: 本次更新涉及到数据库变动, 请做好备份.</strong></div>
					</td>
				</tr>
				{/if}
				{if $upgrade['attachments']}
				<tr>
					<th>文件变动</th>
					<td>
						<div class="help-block"><strong>注意: 重要: 本次更新涉及到程序变动, 请做好备份.</strong></div>
						<div class="alert alert-info" style="line-height:20px;margin-top:20px;">
						{loop $upgrade['attachments'] $line}
						<div><span style="display:inline-block; width:30px;">{if is_file(IA_ROOT . $line)}M{else}A{/if}</span>{$line}</div>
						{/loop}
						</div>
					</td>
				</tr>
				{/if}
				<tr>
					<th>更新协议</th>
					<td>
						<label class="checkbox"><input type="checkbox" id="agreement_0"> 我已经做好了相关文件的备份工作</label>
						<label class="checkbox"><input type="checkbox" id="agreement_1"> 认同官方的更新行为并自愿承担更新所存在的风险</label>
						<label class="checkbox"><input type="checkbox" id="agreement_2"> 理解官方的辛勤劳动并报以感恩的心态点击更新按钮</label>
					</td>
				</tr>
				<tr>
					<th>自动更新</th>
					<td>
						{if $offlineok}
						<input name="do-update" type="submit" value="立即更新(离线更新包已就绪)" class="span4 btn btn-primary" />
						{else}
						<input name="do-update" type="submit" value="立即更新" class="span2 btn btn-primary" /> &nbsp; 
						<input onclick="agreement() && $('#dialog').modal({backdrop:'static'});" type="button" value="下载离线更新包" class="span3 btn" />
						{/if}
						<input type="hidden" name="hash" value="{$hash}" />
						<input type="hidden" name="token" value="{$_W['token']}" />
						<div class="help-block">立即更新当前系统, 如果多次更新均失败, 请尝试使用离线更新包</div>
					</td>
				</tr>
			</table>
			{/if}
		</form>
	</div>
</div>
<div id="dialog" class="modal hide">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h3>离线下载需要验证你的身份</h3>
	</div>
	<form action="" method="post" class="form-horizontal form" target="offline" onsubmit="return validate();">
	<div class="modal-body">
		<table class="tb">
			<tr>
				<td colspan="2">
					<div class="help-block"><strong style="color:red;">离线更新包使用说明: 下载好安装包 upgrade.zip 后, 不要解压缩, 请直接上传至微擎安装目录下 /data 目录下, 然后重新运行升级程序(刷新本页面).</strong></div>
				</td>
			</tr>
			<tr>
				<th>绑定的论坛用户</th>
				<td>
					<input type="text" name="username" class="span3">
					<div class="help-block">请输入在云服务中心注册站点时绑定的论坛用户</div>
				</td>
			</tr>
			<tr>
				<th>绑定的用户密码</th>
				<td>
					<input type="password" name="password" class="span3">
					<div class="help-block">请输入在云服务中心注册站点时绑定的论坛用户密码</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="modal-footer">
		<input type="submit" name="do-download" class="pull-right btn btn-primary span2" value="下载离线更新包">
		<input type="hidden" name="hash" value="{$hash}" />
		<input type="hidden" name="token" value="{$_W['token']}" />
		<iframe name="offline" src="about:blank" style="display:none;"></iframe>
	</div>
	</form>
</div>
<script type="text/javascript">
function agreement() {
	var a = $("#agreement_0").is(':checked');
	var b = $("#agreement_1").is(':checked');
	var c = $("#agreement_2").is(':checked');
	if(a && b && c) {
		return confirm('更新将直接覆盖本地文件, 请注意备份文件和数据. \n\n**另注意** 更新过程中不要关闭此浏览器窗口.');
	} else {
		message("抱歉，更新前请仔细阅读更新协议！", '', 'error');
		return false;
	}
}
function validate() {
	if($.trim($(':text[name="username"]').val()) == '' || $.trim($(':password[name="password"]').val()) == '') {
		message('使用离线升级必须输入的站点绑定的论坛用户资料.', '', 'error');
		return false;
	}
	return true;
}
</script>
{/if}
{if $do == 'history'}
<div class="main">
	<div style="padding:15px;">
		{if empty($ds)}
		<div class="alert alert-info">
			没有需要手动升级的文件
		</div>
		{else}
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="min-width:300px;">版本说明</th>
					<th style="width:160px;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $ds $row}
				<tr>
					<td>Release 版本升级: {$row['title']}</td>
					<td>
						{if $row['error']}
						<a href="{php echo create_url('cloud/upgrade/history', array('foo' => 'delete', 'version' => $row['title']));}">版本已失效, 请删除</a>
						{else}
						{if $row['current']}
						<a href="{php echo create_url('cloud/upgrade/history', array('foo' => 'manual', 'version' => $row['title']));}">升级</a>
						{else}
						升级只能按照版本顺序升级
						{/if}
						{/if}
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		{/if}
	</div>
</div>
{/if}
{template 'common/footer'}
